#include <unistd.h>
#include <vector>
#include <iostream>

using namespace std;

struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};

class Solution {
public:
    bool HasSubtree(TreeNode* p1, TreeNode* p2)
    {
        if (p1 == NULL or p2 == NULL) return false;
        if (not this->contain(p1, p2)) {
            return this->HasSubtree(p1->left, p2) or this->HasSubtree(p1->right,p2);
        } else { return true; }
        
    }
    
    bool contain(TreeNode * p1, TreeNode * p2) {
        if (p2 == NULL) return true;
        if (p1 == NULL) return false;
        if (p1->val != p2->val) return false;
        return this->contain(p1->left, p2->left) and this->contain(p1->right, p2->right);
    }

    vector<int> PrintFromTopToBottom(TreeNode* root) {
        vector< TreeNode * > buf;
        vector<int > res;
        if ( root == NULL ) return res;
        buf.push_back(root);
        while (not buf.empty()) {
            TreeNode * t = buf.front();
            buf.erase(buf.begin());
            res.push_back(t->val);
            if (t->left != NULL) buf.push_back(t->left);
            if (t->right != NULL) buf.push_back(t->right);

        }
        return res;
    }

    
    RandomListNode* ReConnectNodes(RandomListNode* pHead) {
        RandomListNode* p1=pHead;
        RandomListNode* newhead=NULL;
        RandomListNode* p2=NULL;
          
        //初始化
        if(p1!=NULL)
        {
            newhead=p2=p1->next;
            p1->next=p2->next;
            p1=p1->next;
        }
        //循环
        while(p1!=NULL)
        {
            p2->next=p1->next;
            p2=p2->next;
            p1->next=p2->next;
            p1=p1->next;
        }
          
        return newhead;
          
    }
};

int main(int argc, char const *argv[])
{
    Solution a;
    // vector<int > res;
    // res.push_back(1);
    // res.push_back(2);
    // res.push_back(3);
    // res.erase(res.begin());
    // for (auto i : res) cout << i;
    TreeNode n10 = TreeNode(10);
    TreeNode n6 = TreeNode(6);
    TreeNode n14 = TreeNode(14);
    n10.left = &n6;
    n10.right = &n14;
    auto res = a.PrintFromTopToBottom(&n10);
    for ( auto i : res) {
        cout << i << endl; 
    }
    
    return 0;
}
